<template>
	<el-row  v-loading='loading' element-loading-text="拼命加载中">
		
		<!--  搜索操作区 -->
	    <el-row class="pb10  little-header">
	          <el-col :md='18' :lg='14'  >
	                <div class=' w-100 ' align='left'>
	                		<el-select v-model="search.type" placeholder="请选择"  class='w140'>
	          							    <el-option
	          							      v-for="item in typedata"
	          							      :key="item.value"
	          							      :label="item.label"
	          							      :value="item.value">
	          							    </el-option>
	          					</el-select>
	          					<el-select v-model="search.item_state" placeholder="请选择"  class='w140'>
	          							    <el-option
	          							      v-for="item in company_state"
	          							      :key="item.value"
	          							      :label="item.label"
	          							      :value="item.value">
	          							    </el-option>
	          					</el-select>
	                    <el-input  placeholder='请输入名称' v-model.trim='search.name' style='width:28%'></el-input>
	                    <el-button icon="el-icon-search" type='primary' @click='pageInit()'>搜索</el-button>
	                </div>
	          </el-col>
	          <el-col :md='5' :lg='8'  :offset='1' >  
	                <div align="right">
	                        <!-- <router-link to='/project/addNew'><el-button type="primary" icon="el-icon-plus" size="small" round  >新增</el-button></router-link> -->
	                        <!-- <el-button  class='export-icon'               size="small" round   @click="handleExport()"><i class='fa fa-share pr5'></i>导出</el-button> -->
	                </div>
	          </el-col>
	         
	    </el-row>
	    
	    <el-row class='mb20 mt12'>
	    	  <el-breadcrumb separator-class="el-icon-arrow-right">
					  <el-breadcrumb-item  v-for='(item,index) in navarr' :key='index' >
					  		<a href="javascript:void(0)"  @click='jump(item.dirCode,item.name,index)'>{{item.name}}</a>
					  </el-breadcrumb-item>
			  </el-breadcrumb>
	    </el-row>
	    <!-- table -->
	    <el-table border  :data="tableList"   :cell-class-name='hover'  @cell-click='checkUser' >
	        	 
	          <el-table-column prop="name"            label="项目"     align="" >
	          		<template slot-scope='list'  @click='openDetail(list.row)'>
	          			<i  class='icon icon-filefolder  align-text-top' ></i>
	                      {{list.row.name}}
	                </template>
	          </el-table-column>
	          <el-table-column prop="prjType"            label="项目类型"     align="center" >
	                <template slot-scope='list'>
	                      {{list.row.prjType | project_type}}
	                </template>
	          </el-table-column>
	          <el-table-column prop="entMemberType"            label="状态"     align="center"  >
	                <template slot-scope="scope">
	                      {{scope.row.entMemberType | entMember}}
	                </template>
	          </el-table-column>
	          <el-table-column prop="modifyTime"      label="更新时间"     align="center"  >
	                <template slot-scope="scope">
	                      {{scope.row.modifyTime | formatDate}}
	                </template>
	          </el-table-column>
	          <el-table-column prop="cretaeUserName"  label="创建人"       align="center"  ></el-table-column>
	         
	    </el-table>
	    <!-- 分页 -->
	    <el-pagination class='mt28'
	            background
	            @size-change="handleSizeChange"
	            @current-change="handleCurrentChange"
	            :current-page="1"
	            :page-sizes="[10, 20]"
	            :page-size="10"
	            :pager-count="5"
	            layout="total, sizes, prev, pager, next, jumper"
	            :total="Total">
	    </el-pagination>
	    <NewFileJia  ref='NewFileJia'  v-on:save-finished='addNewList(arguments)'></NewFileJia>
	</el-row>
</template>

<script >
//接口
import { contractList,saveFile_folder,saveFile,modify_folder,modify_file,deleteFolder,deleteFile,DetailFile }  from  '@/api/professional_work/contract/index'
//组件
import  NewFileJia  from  '@/components/professional_work/contract/index'
export default {
	name: 'pro_contract',
	data(){
		return {
			/*static*/
			loading:false,
			typedata:[
				{value: '',label: '项目类型'}, 
                {value: '1',label: '收益权类'}, 
                {value: '2',label: '定向融资类'}, 
                {value: '3',label: '资产登记交易类'}, 
                {value: '4',label: '资产转让增值'},
                {value: '5',label: '其他类'}
                ],
			company_state:[
				{label:'项目状态',value:''},
				{label:'进行中',value:'1'},
				{label:'归档',value:'2'},
			],

			/*active*/
			//查询条件
			search:{
				type:'',
				item_state:'',
				dirCode:'',
				limit:10,
				currentPage:1,
			},
			//文件夹导航
			navarr:[],

			tableList:[],
			Total:null,
			
			//文件上传请求地址
      		actionAddress:process.env.BASE_API+'/op/fileupload/upload_file',
		}
	},
	created(){
		//初始化 文件目录 列表
		this.search.dirCode = 'root'
		this.initPath('root','根目录')
    	// this.pageInit()
  	},
	methods:{
		//********初始化********
		pageInit(){
	      this.loading = true

	      contractList(this.search).then(res=>{
	          this.loading = false
	          this.tableList = res.data.dataList
	          this.Total=res.data.totalRs
	      })
	      .catch(error => {
	            this.loading = false
	            that.outputError(error)
	        })
	    },
	    //文件夹 面包屑导航
	    initPath(dirCode,name){
	    	this.navarr.push({name,dirCode})
	    },

	    //********列表操作********
		//新建文件夹
		newFileList(){
			this.$refs.NewFileJia.$emit('openDialog')
		},
		//接收文件名称后  common 接收三个参数 【form（code，name），新增/编辑状态，文件夹/文件重命名】
		addNewList(arg){
			// console.log(arg)
			let data = arg[0]
			let isEdit = arg[1]

			if(isEdit == false){
				//新建文件夹
				saveFile_folder(data,this.search.dirCode).then(res=>{
					this.$message({type:'success',message:res.data.msg})
					this.pageInit()
				})	
			}
			else{
				if(arg[2] == 'folder'){
					//修改文件夹
					modify_folder(data).then(res=>{
						this.$message({type:'success',message:res.data.msg})
						this.pageInit()
					})
				}
				else{
					//修改文件名称
					modify_file(data).then(res=>{
						this.$message({type:'success',message:res.data.msg})
						this.pageInit()
					})
				}
				
			}
			
		},
		//文件夹重命名
		FolderRename(index,row){
			this.$refs.NewFileJia.$emit('openEditDialog',row.name,row.code,'folder')
		},
		//文件重命名
		FileRename(index,row){
			this.$refs.NewFileJia.$emit('openEditDialog',row.name,row.code,'file')
		},
		
		//删除文件夹 
		FolderDelete(index,row){
			this.$confirm('确定删除该文件夹？', '提示', {
	            confirmButtonText: '确定',
	            cancelButtonText: '取消',
	            type: 'warning'
	        })
	        .then(() => {
				deleteFolder(row.code).then(res=>{
					this.$message({type:'success',message:res.data.msg})
					this.pageInit()
				})
			})
		},
		//删除文件
		FileDelete(index,row){
			this.$confirm('确定删除该文件？', '提示', {
	            confirmButtonText: '确定',
	            cancelButtonText: '取消',
	            type: 'warning'
	        })
	        .then(() => {
				deleteFile(row.code).then(res=>{
					this.$message({type:'success',message:res.data.msg})
					this.pageInit()
				})
			})
		},
		//面包屑导航 跳转(回跳)
		jump(code,name,index){
			// console.log(index)
			this.search.dirCode = code
			this.navarr.splice(index+1)
			this.pageInit()
		},
		
	
      	//文件上传成功之后的回调  保存文件
      	handleSuccess(response, file, fileList){
      		console.log(response)
      		 saveFile(response.data.code,response.data.name,this.search.dirCode).then(res=>{
      		 	this.$message({type:'success',message:res.data.msg})
      		 	this.pageInit()
      		 })
      	},

		hover({row, column, rowIndex, columnIndex}){
	    //console.log(row, column, rowIndex, columnIndex)
	    //设置表格第一列的特殊样式  该样式需要在APP 或者 public.css设置
	      if(columnIndex == 0 ){
	        return 'activeCol'
	      }
	    },
	    //点击表格第一列  查看详情
	    checkUser(row, column, cell, event){
	    	if(column.label == '项目'){
	    			this.$router.push({name:'pro_contract_item'})
	    	}
	        
	    },

	    //导出
	    handleExport(){

	    },
	    //
	    /*每页显示条数变化 事件触发
	     *@method 方法名
	     *@for 所属类名
	     *@param{val} 共几条
	     *@return {} 
	    */
	    handleSizeChange(val) {
	      this.search.limit = val;
	      this.pageInit()
	    },
	    /*页数变化 事件触发
	     *@method 方法名
	     *@for 所属类名
	     *@param{val} 第几页
	     *@return {} 
	    */
	    handleCurrentChange(val) {
	      this.search.currentPage = val
	      this.pageInit()
	    },

	},
	components:{
		NewFileJia
	}
}
</script>

<style type="text/css" scoped>
.icon{width: 16px;height: 16px;}
.icon-filefolder{background: url('../../assets/images/img/public/icon-filefolder.png') no-repeat;}
.icon-file{background: url('../../assets/images/img/public/icon-file.png') no-repeat;}
</style>